/*
 * RenderAlice.java
 * 
 * Created on Jun 19, 2007, 8:06:48 PM
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package flyingsaucerpdf;

import java.io.*;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;

import org.xhtmlrenderer.pdf.ITextFontResolver;
import org.xhtmlrenderer.pdf.ITextRenderer;

/**
 *
 * @author joshy
 */
public class RenderAlice {

    public static void main(String[] args) 
            throws IOException, DocumentException {
        String inputFile = "samples/alice/alice.xhtml";
        String url = new File(inputFile).toURI().toURL().toString();
        String outputFile = "alice.pdf";
        File file = new File(outputFile);
        System.out.println(file.getAbsolutePath());
        OutputStream os = new FileOutputStream(file);
        
        ITextRenderer renderer = new ITextRenderer();
        renderer.setDocument(url);
        // 解决中文支持问题  
        ITextFontResolver fontResolver = renderer.getFontResolver();  
        fontResolver.addFont("C:/Windows/Fonts/simsun.ttc", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);  
        renderer.layout();
        renderer.createPDF(os);
        
        os.close();
    }
}
